﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MedicalLog.Domain.Entities;

namespace MedicalLog.Domain.Repositories
{
    public class DoctorRepositorty
    {

        MedicalLogEntities _dbMedicalLog;
        public DoctorRepositorty()
        {
            _dbMedicalLog = new MedicalLogEntities();
        }


        
        public void AddDoctor(Doctor newDoctor)
        {
            _dbMedicalLog.AddToDoctors(newDoctor);
            _dbMedicalLog.SaveChanges();
        }


        public Doctor DeleteDoctor(int id)
        {
            try
            {
                return _dbMedicalLog.Doctors.First(doctor => doctor.IdDoctor == id);
            }
            catch (Exception)
            {

                throw;
            }

        }


        public void DeleteDoctor(Doctor doctor)
        {
            _dbMedicalLog.Doctors.DeleteObject(doctor);
            _dbMedicalLog.SaveChanges();
        }


        public Doctor UpdateDoctor(int id)
        {
            try
            {
                return _dbMedicalLog.Doctors.First(doctor => doctor.IdDoctor == id);
            }
            catch (Exception)
            {

                throw;
            }

        }

        public void UpdateDoctor(Doctor doctor)
        {
            _dbMedicalLog.Doctors.First(d => d.IdDoctor == doctor.IdDoctor);
            _dbMedicalLog.Doctors.ApplyCurrentValues(doctor);
            _dbMedicalLog.SaveChanges();
        }


        public Doctor DetailDoctor(int id)
        {
            try
            {
                return _dbMedicalLog.Doctors.First(doctor => doctor.IdDoctor == id);
            }
            catch (Exception)
            {

                throw;
            }

        }

    }
}
